home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / dirent.lha / dirent / telldir.c < prev    next >
C/C++ Source or Header  |  1988-09-02  |  836b  |  41 lines

  1. /*
  2.     telldir -- report directory stream position
  3.  
  4.     last edit:    25-Apr-1987    D A Gwyn
  5.  
  6.     NOTE:    4.nBSD directory compaction makes seekdir() & telldir()
  7.         practically impossible to do right.  Avoid using them!
  8. */
  9.  
  10. #ifdef unos
  11. #include    <errno.h>
  12. #else
  13. #include    <sys/errno.h>
  14. #endif
  15. #include    <sys/types.h>
  16. #include    <dirent.h>
  17.  
  18. extern off_t    lseek();
  19.  
  20. extern int    errno;
  21.  
  22. #ifndef SEEK_CUR
  23. #define    SEEK_CUR    1
  24. #endif
  25.  
  26. off_t
  27. telldir( dirp )                /* return offset of next entry */
  28.     DIR    *dirp;            /* stream from opendir() */
  29. {
  30.     if ( dirp == NULL || dirp->dd_buf == NULL )
  31.         {
  32.         errno = EFAULT;
  33.         return -1;        /* invalid pointer */
  34.         }
  35.  
  36.     if ( dirp->dd_loc < dirp->dd_size )    /* valid index */
  37.         return ((struct dirent *)&dirp->dd_buf[dirp->dd_loc])->d_off;
  38.     else                /* beginning of next directory block */
  39.         return lseek( dirp->dd_fd, (off_t)0, SEEK_CUR );
  40. }
  41.